#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "debug.h"
#include "i2c_drv.h"
#include "video_adjust.h"

int i2c_test_main(){
    int fd = -1;
    unsigned char buf[256] = {0x09};

    // Open device file
    fd = open("/dev/i2c-1", O_RDWR);
    if(fd < 0)
    {
        printf("Open file error\n");
        goto Exit;
    }
//write
//    i2c_write_bytes(fd,0x39,0xf3, buf, 1);
//read
    i2c_read_bytes_delay(fd,0x39,0xf3, buf, 1);
//    i2c_read_bytes(fd,0x39,0xf3, buf, 1);
//    i2c_read_bytes(fd,0x31,0x18,buf,1);
Exit:
    close(fd);

    return 0;
}

int video_adjust_test_main(){
    char brightness=0;
    unsigned char contrast=0x88;
    unsigned char saturation=0x80;

    pr_db("-1= 0x %x \r\n",(char)-5);
    for(int i=0;i<8;i++){
        pr_db("video_read_brightness 0x%x\n", video_read_brightness(i));
        pr_db("video_read_contrast 0x%x\n", video_read_contrast(i));
        pr_db("video_read_saturation 0x%x\n", video_read_saturation(i));
    }
//brightness : 0x0
//contrast: default 0x88;
//saturation: default 0x80;
    while(1){
        brightness=brightness-10;
        contrast=contrast+10;
        saturation=saturation-10;
        for(int i=0;i<8;i++){
//            video_adjust_brightness(i,brightness);
//            video_adjust_contrast(i,contrast);
            video_adjust_saturation(i,saturation);
        }
        pr_db("video_read_brightness:0x%x\n",brightness);
        pr_db("video_adjust_contrast:0x%x\n",contrast);
        pr_db("saturation:0x%x\n",saturation);
        sleep(2);
    }

    return 0;
}

int main(int argc, char* argv[])
{
    setbuf(stdout,NULL);
//  i2c test;
//    i2c_test_main();
//  video test;
    video_adjust_test_main();
    return 0;
}
